<template>
  <div class="svg-icon">
    <svg
      aria-hidden="true"
      :style="`width: ${size}px;height: ${size}px;transform: rotate(${rotate}deg);`"
    >
      <use :xlink:href="symbolId" :fill="colorCpt" />
    </svg>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: 'SvgIcon',
})
import { computed, reactive } from 'vue'

const props = defineProps({
  prefix: {
    type: String,
    default: 'icon',
  },
  name: {
    type: String,
    required: true,
  },
  color: {
    type: String,
    default: '',
  },
  size: {
    type: [Number, String],
    default: '18',
  },
  rotate: {
    type: [Number, String],
    default: 0,
  },
  active: {
    type: Boolean,
    default: false,
  },
})
const state: any = reactive({
  defaultColor: '#A7ADB9',
})
const symbolId = computed(() => `#${props.prefix}-${props.name}`)
const colorCpt = computed(() => {
  if (props.color) {
    return props.color
  }
  if (props.active) {
    return 'var(--czr-main-color)'
  }
  return state.defaultColor
})
</script>

<style scoped>
.svg-icon {
  vertical-align: -0.15em;
  overflow: hidden;
  fill: currentColor;
}
</style>
